package domain.entities;

import org.apache.commons.codec.digest.DigestUtils;

import javax.persistence.*;

/**
 * Created with IntelliJ IDEA.
 * User: nico
 * Date: 22/10/12
 * Time: 12:46
 * To change this template use File | Settings | File Templates.
 */
@Entity
public class RemoteAccess {

    private String hash;
    private boolean active;
    private Centro centro;

    public RemoteAccess(){
        hash = generateHashCode();
        active = true;
    }

    @Id
    public String getHash() {
        return hash;
    }

    public void setHash(String hash) {
        this.hash = hash;
    }

    @Column(name = "active")
    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    @OneToOne(cascade = CascadeType.ALL, mappedBy = "remoteAccess")
    public Centro getCentro() {
        return centro;
    }

    public void setCentro(Centro centro) {
        this.centro = centro;
    }

    private String generateHashCode(){
        Float big = 1000000000.0f;
        Integer random = (int) (Math.random() * big);
        return DigestUtils.shaHex(random.toString());
    }

}
